﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace GameUnit
{
    public static class WeaponManager
    {
        public static Hashtable WeaponsTable;

        public static void Load(string weaponFilePath)
        {
            WeaponsTable = (Hashtable)SGLisp.Helper.EvalValueFromFile(weaponFilePath, SGLisp.RT.MainContext);
           
        }

        public static Hashtable GetWeapon(string key)
        {
            return (Hashtable)WeaponsTable[key];
        }
        public static Weapon CreateWeapon(Hashtable weaponConfig,Unit unit = null)
        {
            Object WeaponPrefab = Resources.Load((string)weaponConfig[":prefab"]);
            if (WeaponPrefab == null)
            {
                Debug.LogError("没有找到武器预设" + (string)weaponConfig[":prefab"]);
                return null;
            }
            GameObject newWeaponG = (GameObject)GameObject.Instantiate(WeaponPrefab);
            Weapon newWeapon = newWeaponG.AddComponent<Weapon>();
            //newWeapon.Init(weaponConfig,unit); 
            return newWeapon;
        }
    }
}